// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: io.cpp 225 2008-09-12 17:43:02Z heavyzheng $
//

#ifndef ZZHENG_QUANT_DATES_SOURCE
#define ZZHENG_QUANT_DATES_SOURCE
#endif // ZZHENG_QUANT_DATES_SOURCE

#include <zzheng/quant/dates/io.hpp>
#include <zzheng/quant/dates/date.hpp>
#include <zzheng/quant/dates/duration.hpp>
#include <zzheng/quant/dates/adjusted_date.hpp>
#include <zzheng/quant/dates/schedule.hpp>
#include <zzheng/quant/dates/function.hpp>

#include <string>
#include <iostream>

namespace zzheng {
namespace quant {
namespace dates {

    std::ostream& operator<<(std::ostream& os, const date& d) {
        os << d.str();
        return os;
    }

    std::istream& operator>>(std::istream& is, date& d) {
        std::string str;
        is >> str;
        try {
            d = parse_date(str);
        } catch (...) {
            d = date();
            is.setstate(std::ios::failbit);
        }
        return is;
    }

    std::ostream& operator<<(std::ostream& os, const duration& d) {
        os << d.str();
        return os;
    }

    std::istream& operator>>(std::istream& is, duration& d) {
        std::string str;
        is >> str;
        try {
            d = parse_duration(str);
        } catch (...) {
            d = duration();
            is.setstate(std::ios::failbit);
        }
        return is;
    }

    std::ostream& operator<<(std::ostream& os, const adjusted_date& ad) {
        return ( os << ad.adjusted() << "|" << ad.unadjusted() );
    }

    std::ostream& operator<<(std::ostream& os, const adjusted_period& ap) {
        return ( os << "(" << ap.first << "," << ap.second << ")" );
    }

} // namespace zzheng::quant::dates
} // namespace zzheng::quant
} // namespace zzheng



